<?php

Yii::import('admin.models._base.BaseCategory');

class Category extends BaseCategory
{
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}

	public function tableName() {
		return 'category';
	}

	public function relations() {
		return array(
			'sub' => array(self::HAS_MANY, 'Category', 'parent_id'),
		);
	}

	public function behaviors()
	{
		return array(
			'ml' => array(
				'class' => 'application.modules.admin.models.behaviors.MultilingualBehavior',
				'localizedAttributes' => array('title'),
				'langClassName' => 'CategoryLang',
				'langTableName' => 'category_lang',
				'languages' => Yii::app()->params['translatedLanguages'],
				'defaultLanguage' => Yii::app()->params['defaultLanguage'],
				'langForeignKey' => 'owner_id',
				'dynamicLangClass' => true,
			),
		);
    }

	public function defaultScope()
	{
		return $this->ml->localizedCriteria();
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('t.id', $this->id);
		$criteria->compare('t.title', $this->title, true);
		$criteria->compare('t.order', $this->title, true);
		$criteria->compare('t.filter', $this->title, true);
		$criteria->compare('t.main', $this->title, true);
		$criteria->compare('t.img', $this->title, true);
		//...
		//here your criteria definition
		//...

		return new CActiveDataProvider($this, array(
			'criteria'=>$this->ml->modifySearchCriteria($criteria),
			//instead of
			//'criteria'=>$criteria,
		));
	}
}